﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Bll;
using Kaidou.Persister;
using Kaidou.Model;
using System.Collections.Generic;

public partial class seal_seal_receipt_order : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = (LoginModel)Session["loginModel"];

        if (loginModel == null)
        {
            Response.Redirect("../login.aspx");
            return;
        }
        
        if (loginModel.isKumiaiin() && sessioncontrol.control())
        {
            Response.Redirect("../control.aspx");
        }


        TRN_ReceiptOrderManager2 manager = TRN_ReceiptOrderManager2.checkout(Resources.Resource.ResourceManager);
        if (manager == null)
        {
            this.lbl_msg.Text = "■確認シール受付の再処理中です。";

        }
        else
        {
            TRN_Juchu_UketukePersister perU = new TRN_Juchu_UketukePersister();
            bool isReceiptOrderTerminate = perU.isReceiptOrderTerminate();
            if (isReceiptOrderTerminate)
            {
                this.lbl_msg.Text = "■"+perU.getTime0030().ToString("yyyy年MM月dd日 tt HH:mm")+" までの注文受付データは処理を完了しています。";


            }
            else
            {
                this.lbl_msg.Text = "■未処理のデータ";
                this.lbl_msg2.Text = perU.getTime0030().ToString("yyyy年MM月dd日 tt HH:mm") + " までの受付分。";

                this.tb_data.Rows.Clear();

                HtmlTableRow title = new HtmlTableRow();
                title.Cells.Add(newTitleCell("20%", "受注No."));
                title.Cells.Add(newTitleCell("15%", "行No."));
                title.Cells.Add(newTitleCell("35%", "販売業者登録証番号"));
                title.Cells.Add(newTitleCell("30%", "確認シール枚数"));
                this.tb_data.Rows.Add(title);

                List<TrnJuchud> list_TrnJuchud = perU.findReceiptOrderTarget();
                for (int i = 0; i < list_TrnJuchud.Count; i++)
                {
                    TrnJuchud d = list_TrnJuchud[i];
                    String trader_reg_no = d.TraderRegNo;

                    HtmlTableRow row = new HtmlTableRow();
                    row.Cells.Add(newRowCell("20%", "center", d.Id.JuchuNo));
                    row.Cells.Add(newRowCell("15%", "right", d.Id.JuchuRecNo.ToString()));
                    row.Cells.Add(newRowCell("35%", "center", trader_reg_no));
                    row.Cells.Add(newRowCell("30%", "right", d.SealQty.ToString()));
                    this.tb_data.Rows.Add(row);

                }

            }
            TRN_ReceiptOrderManager2.checkin();
            manager = null;
        }
    }

    private HtmlTableCell newTitleCell(string in_width, string in_InnerText)
    {
        HtmlTableCell t1 = new HtmlTableCell();
        t1.Width = in_width;
        t1.NoWrap = true;
        t1.BgColor = "#f5f5dc";
        t1.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
        t1.InnerText = in_InnerText;
        return t1;
    }

    private HtmlTableCell newRowCell(string in_width, string in_align, string in_InnerText)
    {
        HtmlTableCell t1 = new HtmlTableCell();
        t1.Width = in_width;
        t1.BgColor = "#FFFFFF";
        t1.Align = in_align;
        t1.InnerText = in_InnerText;
        return t1;
    }
}
